package com.zjdiepu.www.common.util;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

/**
 * 类DateUtil.java的实现描述：日期转换
 * 
 * @author
 */
public class DateUtil {
	
	//时间戳
    public static int dateConvertTimeStamp(String time, String formant) throws Exception {
        int re_time = 0;
        SimpleDateFormat sdf = new SimpleDateFormat(formant);
        Date date = sdf.parse(time);
        long l = date.getTime();
        re_time = (int) (l / 1000);
        return re_time;
    }
    
	/**
	 * 获取周一(中国习惯定义)
	 * @param date
	 * @return
	 */
	public static Date getMonday(Date date) {
		if(null == date) {
			return null;
		}
		
		Integer i = getWeekOfDay(date);
	 	switch (i) {
		case 1:
			return increaseDate(date, -6);
		default:
			return increaseDate(date, 2-i);
		}
	}
	/**
	 * 获取周日(中国习惯定义)
	 * @param date
	 * @return
	 */
	public static Date getSunday(Date date) {
		if(null == date) {
			return null;
		}
		Integer i = getWeekOfDay(date);
	 	switch (i) {
		case 1:
			return date;
		default:
			return increaseDate(date, 8-i);
		}
	}
	
	/**
	 * 获取日期在星期中第几天
	 * @param date
	 * @return
	 */
	public static Integer getWeekOfDay(Date date) {
		if(null == date) {
			return null;
		}
		Calendar aCalendar = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
		aCalendar.setTime(date);
	 	Integer i = aCalendar.get(Calendar.DAY_OF_WEEK);
	 	return i;
	}
	
	/** 
     * 根据日期获得星期 
     * @param date 
     * @return 
     */ 
	public static String getWeekOfDate(Date date) { 
	  String[] weekDaysName = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; 
	  Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai")); 
	  calendar.setTime(date); 
	  int intWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1; 
	  return weekDaysName[intWeek]; 
	} 
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title: truncAndAddDays  <br/>
	 * @Description: 时间截取到日，并累加日 <br/>
	 * @param date
	 * @param amount
	 * @return
	 * @version V1.0  <br/>
	 */
	public static Date truncAndAddDays(Date date, int amount) {
		if(null == date) {
			return null;
		}
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		try {
			date = simpleDateFormat.parse(simpleDateFormat.format(date));
			Calendar cd = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
			cd.setTime(date);
			cd.add(Calendar.DATE, amount);
			return cd.getTime();
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title: truncAndAddYearDays  <br/>
	 * @Description: 时间截取到日，并累加年,日 <br/>
	 * @param date
	 * @param amount
	 * @return
	 * @version V1.0  <br/>
	 */
	public static Date truncAndAddYearDays(Date date, int year, int day) {
		if(null == date) {
			return null;
		}
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		try {
			date = simpleDateFormat.parse(simpleDateFormat.format(date));
			Calendar cd = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
			cd.setTime(date);
			cd.add(Calendar.YEAR, year);
			cd.add(Calendar.DATE, day);
			return cd.getTime();
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}

    /**
     * 时间是否在配置时间之前
     * 
     * @param configDate
     * @param entryDate
     * @return
     */
    public static boolean isBefore(Date configDate, Date entryDate) {
        boolean bool = entryDate.before(configDate);
        return bool;
    }

    /**
     * 时间是否在配置时间之后
     * 
     * @param configDate
     * @param entryDate
     * @return
     */
    public static boolean isAfter(Date configDate, Date entryDate) {
        boolean bool = entryDate.after(configDate);
        return bool;
    }

    /**
     * 将字符串时间转换成Date类型
     * 
     * @param str
     * @return
     */
    public static Date convertStr2Date(String str) {
        Date date = null;
        if(StringUtils.isBlank(str)){
        	return null;
        }
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            date = sdf.parse(str);
        } catch (ParseException e) {
            date = null;
        }
        return date;
    }

    /**
     * 将字符串时间转换成Date类型
     * 
     * @param str
     * @return
     */
    public static Date convertStr3Date(String str) {
        Date date = null;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            date = sdf.parse(str);
        } catch (ParseException e) {
            date = null;
        }
        return date;
    }

    /**
	 * 获得分级的时间
	 */
	public static String getMMTime() {
		DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
		return dateFormat.format(new Date());
	}
	
    /**
     * 字符串转日期
     * 
     * @param str
     * @return
     */
    public static Date StringToDate(String str) {
        DateFormat formate = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return formate.parse(str);
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * 加减天数
     * 
     * @param date
     * @return Date
     */
    public static Date increaseDate(Date date, int days) {
    	//xiongxiaotun 添加兼容null
    	if(null == date){
    		return null;
    	}
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
        cal.setTime(date);
        cal.add(Calendar.DAY_OF_MONTH, days);
        return cal.getTime();
    }

    /**
     * 加减小时
     * 
     * @param date
     * @return Date
     */
    public static Date increaseHour(Date date, int hours) {
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
        cal.setTime(date);
        cal.add(Calendar.HOUR_OF_DAY, hours);
        return cal.getTime();
    }
    
    /**
     * 加减分钟
     * 
     * @param date
     * @return Date
     */
    public static Date increaseMinute(Date date, int minute) {
    	//xiongxiaotun 添加兼容null
    	if(null == date){
    		return null;
    	}
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
        cal.setTime(date);
        cal.add(Calendar.MINUTE, minute);
        return cal.getTime();
    }

    /**
     * 获取当月最后一天
     * 
     * @param date
     * @return
     */
    public static Date lastDayByMonth(Date date) {
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
        cal.setTime(date);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
        return cal.getTime();
    }

    /**
     * 获取当前月份
     * 
     * @param date
     * @return
     */
    public static Integer getMonth(Date date) {
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
        cal.setTime(date);
        return cal.get(Calendar.MONTH) + 1;
    }
    

    /**
     * yyyy-MM-dd
     * 
     * @param date
     * @return
     */
    public static String dateTo8String(Date date) {
        if (date == null) {
            return null;
        }
        String dates = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        dates = sdf.format(date);
        return dates;
    }

    /**
     * yyyy年MM月dd日 HH时mm分ss秒
     * 
     * @param date
     * @return
     */
    public static String dateTo14StringCH(Date date) {
        String dates = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
        dates = sdf.format(date);
        return dates;
    }

    /**
     * yyyy年MM月dd日 HH:mm:ss
     * 
     * @param date
     * @return
     */
    public static String dateTo8StringCH(Date date) {
        String dates = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日  HH:mm:ss");
        dates = sdf.format(date);
        return dates;
    }

    /**
     * yyyy-MM-dd HH:mm:ss
     * 
     * @param date
     * @return
     */
    public static String dateTo14String(Date date) {
        String dates = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        dates = sdf.format(date);
        return dates;
    }

    /**
     * yyyy-MM-dd HH:mm
     * 
     * @param date
     * @return
     */
    public static String dateTo12String(Date date) {
        String dates = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        dates = sdf.format(date);
        return dates;
    }

    /**
     * yyyyMMdd
     * 
     * @param date
     * @return
     */
    public static String dateTo8Str(Date date) {
        String dates = null;
        if(date == null) {
        	return dates;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        dates = sdf.format(date);
        return dates;
    }

    /**
     * HHmmss
     * @param date
     * @return
     */
    public static String dateTo6Str(Date date) {
        if (date == null) {
            return null;
        }
        String dates = null;
        SimpleDateFormat sdf = new SimpleDateFormat("HHmmss");
        dates = sdf.format(date);
        return dates;
    }
    
    /**
     * yyyy/MM/dd
     * 
     * @param date
     * @return
     */
    public static String dateTo8String2(Date date) {
        String dates = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        dates = sdf.format(date);
        return dates;
    }
    
    /**
     * yyyy-MM-dd
     * 
     * @param date
     * @return
     */
    public static String dateTo8String3(Date date) {
    	if(date == null){
    		return null;
    	}
        String dates = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        dates = sdf.format(date);
        return dates;
    }

    /**
     * yyyyMMdd
     * 
     * @param date
     * @return
     */
    public static Integer dateTo8Integer(Date date) {
        String dates = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        dates = sdf.format(date);
        return Integer.valueOf(dates);
    }

    /**
     * yyyyMMdd
     * 
     * @param str
     * @return
     */
    public static Date string8ToDate(String str) {
        Date date = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        try {
            date = sdf.parse(str);
        } catch (ParseException e) {
            date = null;
        }
        return date;
    }

    /** 判断主方法 */
    public static boolean validate(String dateString) {
        // 使用正则表达式 测试 字符 符合 dddd-dd-dd 的格式(d表示数字)
        Pattern p = Pattern.compile("\\d{4}+\\d{1,2}+\\d{1,2}+");
        Matcher m = p.matcher(dateString);
        if (!m.matches()) {
            return false;
        }

        // 得到年月日
        int year = Integer.valueOf(dateString.substring(0, 4));
        int month = Integer.valueOf(dateString.substring(4, 6));
        int day = Integer.valueOf(dateString.substring(6, 8));

        if (month < 1 || month > 12) {
            return false;
        }
        int[] monthLengths = new int[] { 0, 31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        if (isLeapYear(year)) {
            monthLengths[2] = 29;
        } else {
            monthLengths[2] = 28;
        }
        int monthLength = monthLengths[month];
        if (day < 1 || day > monthLength) {
            return false;
        }
        return true;
    }

    /** 是否是闰年 */
    private static boolean isLeapYear(int year) {
        return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
    }

    public static Date now() {
        return new Date();
    }

    /**
     * 根据年月日拼装日期
     * 
     * @param year
     * @param month
     * @param day
     * @return
     */
    public static Date getDate(String year, String month, String day) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String str = year + "-" + month + "-" + day;
        Date date = null;
        try {
            date = sdf.parse(str);
        } catch (ParseException e) {
            date = null;
        }
        return date;
    }

    /**
     * 比较两个日期相差多少天
     * 
     * @param fDate
     * @param oDate
     * @return
     */
    public static int countDiffDateDays2(Date fDate, Date oDate) {
        Calendar aCalendar = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
        aCalendar.setTime(fDate);
        int day1 = aCalendar.get(Calendar.DAY_OF_YEAR);
        aCalendar.setTime(oDate);
        int day2 = aCalendar.get(Calendar.DAY_OF_YEAR);
        return (day2 - day1);
    }

    public static int countDiffDateDays(Date fDate, Date oDate) {
        Calendar aCalendar = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
        aCalendar.setTimeInMillis(0);
        aCalendar.setTime(fDate);
        fDate = getDate(aCalendar.get(Calendar.YEAR), aCalendar.get(Calendar.MONTH),
                        aCalendar.get(Calendar.DAY_OF_YEAR));
        aCalendar.setTime(oDate);
        oDate = getDate(aCalendar.get(Calendar.YEAR), aCalendar.get(Calendar.MONTH),
                        aCalendar.get(Calendar.DAY_OF_YEAR));
        long quot = (oDate.getTime() - fDate.getTime()) / 1000 / 60 / 60 / 24;
        if (quot < 0) {
            quot = -quot;
        }
        return (int)quot;
    }
    /**
     * 前一个日记比后一个日期多几天
     * @param fDate
     * @param oDate
     * @return
     */
    public static int countDiffDays(Date fDate, Date oDate) {
        Calendar aCalendar = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
        aCalendar.setTimeInMillis(0);
        aCalendar.setTime(fDate);
        fDate = getDate(aCalendar.get(Calendar.YEAR), aCalendar.get(Calendar.MONTH),
                        aCalendar.get(Calendar.DAY_OF_YEAR));
        aCalendar.setTime(oDate);
        oDate = getDate(aCalendar.get(Calendar.YEAR), aCalendar.get(Calendar.MONTH),
                        aCalendar.get(Calendar.DAY_OF_YEAR));
        long quot = (fDate.getTime() - oDate.getTime()) / 1000 / 60 / 60 / 24;
        return (int)quot;
    }

    public static Date getDate(int year, int month, int day) {
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month);
        cal.set(Calendar.DAY_OF_YEAR, day);
        cal.set(Calendar.HOUR, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }

    /**
     * 过滤掉日期中的时分秒，保留年月日
     * 
     * @param date
     * @return
     */
    public static Date convertDate2Date(Date date) {
        String dateStr = dateTo8String(date);
        Date adate = convertStr2Date(dateStr);
        return adate;
    }

    /**
     * 获取日期年
     * 
     * @param date
     * @return
     */
    public static int getYear(Date date) {
        Calendar aCalendar = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
        aCalendar.setTime(date);
        return aCalendar.get(Calendar.YEAR);
    }
    
    /**
     * 今天星期
     * 
     * @param date
     * @return
     */
    public static int getWeekOfYear(Date date) {
        Calendar aCalendar = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
        aCalendar.setTime(date);
        return aCalendar.get(Calendar.WEEK_OF_YEAR);
    }
    /**
     * 今天几号
     * 
     * @param date
     * @return
     */
    public static int getDay(Date date) {
        Calendar aCalendar = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
        aCalendar.setTime(date);
        return aCalendar.get(Calendar.DATE);
    }
    
    /**
     * 说明：对两个日期进行比较(只比较日期，不比较时间)
     * 
     * @param date1
     * @param date2
     * @return
     * @author canghai
     */
    public static int compareOnlyDate(Date date1, Date date2) {
        String date1str = dateTo8String(date1);
        Date newDate1 = convertStr2Date(date1str);
        String date2str = dateTo8String(date2);
        Date newDate2 = convertStr2Date(date2str);
        return newDate1.compareTo(newDate2);
    }

    /**
     * 说明：对两个日期进行比较(long与date)
     * 
     * @param date1
     * @param date2
     * @return
     */
    public static boolean compareDate(Long date1, Date date2) {
        if (date1 == null && date2 == null) return true;
        else if (date1 == null && date2 != null) return false;
        else if (date1 != null && date2 == null) return false;
        else {
            if (date1.longValue() == date2.getTime()) return true;
            return false;
        }
    }

    /**
     * 说明：求两个日期时间差
     * 
     * @param date1
     * @param date2
     * @return
     * @author canghai
     */
    public static long getBetweenDays(Date date1, Date date2) {
        if (date2.before(date1)) {// 保证date1在date2之前
            Date date3 = date1;
            date1 = date2;
            date2 = date3;
        }
        long to = date1.getTime();
        long from = date2.getTime();
        return (from - to) / (1000 * 60 * 60 * 24);
    }

    /**
     * 说明：格式化时间
     * 
     * @param date
     * @param format 格式
     * @return
     * @author canghai
     */
    public static String dateToFormat(Date date, String format) {
        String dates = null;
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        dates = sdf.format(date);
        return dates;
    }

    /**
     * 说明：根据传入日期获取前一天日期
     * 
     * @param date
     * @return
     * @author canghai
     */
    public static Date getTheDayBefore(Date date) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(Calendar.DATE, -1);
        Date beforeDate = calendar.getTime();
        return beforeDate;
    }

    /**
     * 说明：根据传入日期获取后一天日期
     * 
     * @param date
     * @return
     * @author canghai
     */
    public static Date getTheDayAfter(Date date) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(Calendar.DATE, 1);
        Date afterDate = calendar.getTime();
        return afterDate;
    }

    /**
     * 说明：加减天数并转换为Timestamp 类型时间
     * 
     * @param date
     * @param days
     * @return
     * @author canghai
     */
    public static Timestamp increaseDateAndToTimestamp(Date date, Number days) {
        Timestamp timestamp = null;
        if (date == null) {
            return timestamp;
        }
        int intDays = days.intValue();
        Date increaseDate = DateUtil.increaseDate(date, intDays);
        timestamp = new Timestamp(increaseDate.getTime());
        return timestamp;
    }

    /**
     * 方法说明：将util.date转换为Timestamp
     * 
     * @param date
     * @return Timestamp
     * @time 2015年9月18日 上午9:46:08
     * @author canghai
     */
    public static Timestamp dateToTimestamp(Date date) {
        Timestamp timestamp = null;
        if (date == null) {
            return timestamp;
        }
        timestamp = new Timestamp(date.getTime());
        return timestamp;
    }

    /**
     * 方法说明：将Timestamp转换成string MM-dd 格式
     * 
     * @param timestamp
     * @return String
     * @time 2015年8月24日 上午10:10:25
     * @author canghai
     */
    public static String timestampToSMMdd(Timestamp timestamp) {
        if (timestamp == null) {
            return null;
        }
        Date date = new Date(timestamp.getTime());
        String dateStr = dateToFormat(date, "MM-dd");
        return dateStr;
    }

    /**
     * 方法说明：将Timestamp转换成string MM-dd 格式
     * 
     * @param timestamp
     * @return String
     * @time 2015年8月24日 上午10:10:25
     * @author canghai
     */
    public static String timestampToSYYYYMMdd(Timestamp timestamp) {
        if (timestamp == null) {
            return null;
        }
        Date date = new Date(timestamp.getTime());
        String dateStr = dateToFormat(date, "yyyy-MM-dd");
        return dateStr;
    }

    /**
     * 方法说明：将Timestamp转换成string yyyy-MM-dd HH:mm:ss 格式
     * 
     * @param timestamp
     * @return String
     * @time 2015年8月24日 上午10:10:25
     * @author zhucc
     */
    public static String timestampTo14String(Timestamp timestamp) {
        if (timestamp == null) {
            return null;
        }
        Date date = new Date(timestamp.getTime());
        String dateStr = dateTo14String(date);
        return dateStr;
    }

    /**
     * 说明：计算两个时间差:分为秒，分，时，天，月，年
     * 
     * @param timeStart long
     * @param timeEnd long
     * @return returnStr 返回时间差字符
     * @time 2015年10月22日
     * @author canghai
     */
    public static String calcDateDifference(long timeStart, long timeEnd) {
        long between = 0;
        String returnStr = "";
        between = timeEnd - timeStart;// 得到两者的毫秒数

        long second = 1000;// 一秒的毫秒数
        long minute = 60 * second;// 一分钟的毫秒数
        long hour = minute * 60;// 一小时的毫秒数
        long day = hour * 24;// 一天的毫秒数
        long month = day * 30;// 一月的毫秒数
        long year = month * 12;// 一年的毫秒数

        if (between >= 0 && between < second) {
            returnStr = "刚刚";
        } else if (second >= 0 && between < minute) {
            returnStr = between / second + "秒前";
        } else if (between >= minute && between < hour) {
            returnStr = between / minute + "分钟前";
        } else if (between >= hour && between < day) {
            returnStr = between / hour + "小时前";
        } else if (between >= day && between < month) {
            returnStr = between / day + "天前";
        } else if (between >= month && between < year) {
            returnStr = between / month + "个月前";
        } else if (between >= year) {
            returnStr = between / year + "年前";
        }
        return returnStr;
    }

    /**
     * 说明方法描述：将字符串转为date
     * 
     * @param str
     * @return
     * @throws Exception
     * @time 2016年1月18日
     * @author canghai
     */
    public static Date strToDate(String str) throws Exception {
        if (StringUtils.isBlank(str)) {
            return null;
        }
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(str);
    }

    /**
     * 说明方法描述：将字符串转为Timestamp
     * 
     * @param str
     * @return
     * @throws Exception
     * @time 2016年1月18日
     * @author canghai
     */
    public static Timestamp strToTimestamp(String str) throws Exception {
        if (StringUtils.isBlank(str)) {
            return null;
        }
        Timestamp timestamp = new Timestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(str).getTime());
        return timestamp;
    }
    
    /** 
    * @author zhangzj
    * @Title: strToTimestamp 
    * @Description: 字符串转timestamp 
    * @param @param str
    * @param @param formart
    * @param @return
    * @param @throws Exception    设定文件 
    * @return Timestamp    返回类型 
    * @version V1.0
    * @throws 
    */
    public static Timestamp strToTimestamp(String str,String formart) throws Exception {
        if (StringUtils.isBlank(str)) {
            return null;
        }
        Timestamp timestamp = new Timestamp(new SimpleDateFormat(formart).parse(str).getTime());
        return timestamp;
    }
    public static Timestamp dataToTimestamp(Date date) throws Exception {
        if (null == date) {
            return null;
        }
        Timestamp timestamp = new Timestamp(date.getTime());
        return timestamp;
    }
	/**
	 * 日期加月
	 * @param date
	 * @param amount
	 * @return
	 * @author bianyadong
	 * @date 2016年12月13日下午3:26:32
	 */
	public static Date addMonths(Date date, int amount) {
		Calendar cd = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
		cd.setTime(date);
		cd.add(Calendar.MONTH, amount);
		return cd.getTime();
	}
    
	/**
	 * 获取一个时间段的所有日期
	 *      dateBegin <= date  <dateEnd
	 * @param dateBegin
	 * @param dateEnd
	 * @param reportDateformat 日期格式
	 * @return
	 * @author bianyadong
	 */
	public static List<String> getDatePeriod(Date dateBegin, Date dateEnd,String reportDateformat){
		
        if (dateBegin == null) {
            return null;
        }    
        if (dateEnd == null) {
            return null;
        }
        DateFormat dateFormat= null;
		if(StringUtils.isNotBlank(reportDateformat) && "MM/dd".equals(reportDateformat)){
			 dateFormat = new SimpleDateFormat("MM/dd");
		}else{
			 dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		}
		List<String> datePeriodList = new ArrayList<String>();
		while(dateEnd.after(dateBegin)){		
			datePeriodList.add(dateFormat.format(dateBegin.getTime()));
			dateBegin = increaseDate(dateBegin, 1);
		}
		return datePeriodList;
	}
	

	
	/**
    * 获取当前时间
    * @return
    */
    public static Date getCurrentDate() {
    	Calendar cd = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
    	return cd.getTime();
	}
	
	
}
